package com.lagouedu.demoredis.service.impl;

import com.google.common.cache.Cache;
import com.lagouedu.demoredis.config.InitCache;
import com.lagouedu.demoredis.service.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisCluster;

@Service
public class MenusServiceImpl implements MenuService {
    Logger logger = LoggerFactory.getLogger(MenusServiceImpl.class);

    @Autowired
    private JedisCluster jedisCluster;

    @Autowired
    private Cache cache;


    @Override
    public String getMenus() {
        String menus = jedisCluster.get("menus");
        logger.info("从redis中获取数据：{}",menus);
        // 如果redis中没有 则 取本地缓存中的数据
        if(menus == null || "".equals(menus)){
            menus = (String) cache.getIfPresent("menus");
            logger.info("从Guava中获取数据：{}",menus);
        }
        return menus;
    }

    @Override
    public void updateMenus() {

    }
}
